//
// Created by xbm on 23-3-10.
//

#ifndef WEBSERVER_EVENTLOOP_H
#define WEBSERVER_EVENTLOOP_H
#include <memory>
#include "nonCopyable.h"
#include "concurrentQueue.h"
#include "event.h"

namespace event {
class EventLoop : util::NonCopyable {
public:
    static EventLoop &getInstance() {
        static EventLoop el;
        return el;
    }

    void init();

    void close();

    void loopBackground();

    void addEvent(shared_ptr<Event>);

private:
    util::ConcurrentQueue<shared_ptr<Event>> events_;

    EventLoop();

    ~EventLoop();

    void loop();

    bool done_ = false;
};
}
#endif //WEBSERVER_EVENTLOOP_H
